#include <iostream>
#include "udp_client.h"

int main(int argc, char *argv[])
{

    if (argc != 7)
    {

        lg(Error, "Please provide format: <server_ip> <server-port>"
                  "<file-name><receiver-window><control-parm><drop/delay%>");
        exit(-1);
    }
    // 这里可以使用智能指针优化
    safe_udp::UdpClient *udp_client = new safe_udp::UdpClient();

    // 记录从命令行赋予的客户端信息
    std::string server_ip(argv[1]);
    std::string port_num(argv[2]);
    std::string file_name(argv[3]);
    udp_client->receiver_window_ = atoi(argv[4]);

    int control_param = atoi(argv[5]);//控制参数

    lg(Info, "control_param:%d", control_param);

    if (control_param == 0)
    {

        udp_client->is_delay_ = false;
        udp_client->is_packet_drop_ = false;
    }
    else if (control_param == 1)
    {

        udp_client->is_delay_ = false;
        udp_client->is_packet_drop_ = true;
    }
    else if (control_param == 2)
    {

        udp_client->is_delay_ = true;
        udp_client->is_packet_drop_ = false;
    }
    else if (control_param == 3)
    {

        udp_client->is_delay_ = true;
        udp_client->is_packet_drop_ = true;
    }
    else
    {

        lg(Error, "Invalid argument,should be range in 0,1,2 or 3");
        return 0;
    }

    int drop_percentage = atoi(argv[6]);//丢包率
    udp_client->prob_value_ = drop_percentage;

    udp_client->CreateSocketAndServerConnection(server_ip, port_num);
    udp_client->SendFileRequest(file_name);

    free(udp_client);
    return 0;
}